function [out]=drawEllipse(mat,xoff,yoff,a,b,rotation,intensity)
%mat matrix in welche die Ellipse gezeichnet wird
%xoff, yoff .. Kreismittelpunkt
%a,b = Laenge und Breite der Ellipse
%rotation = Rotation der Ellipse in Grad (0-360)
%intensity = strichstaerke
%Es wird eine abgewandelte Form des Bresenham-Algorithmus verwendet
rotation=rotation/180*pi;

dx=0;
dy=b;

a2=a*a;
b2=b*b;
err=b2-(2*b-1)*a2;


while dy>=0
  
   dist=sqrt(dx*dx+dy*dy);
   alpha=-asin(dy/dist);
   beta=-alpha;
   alpha=alpha-rotation;
   beta=beta-rotation;

   X1=uint16(xoff+cos(alpha)*dist);
   Y1=uint16(yoff+sin(alpha)*dist);
   X2=uint16(xoff-cos(alpha)*dist);
   Y2=uint16(yoff-sin(alpha)*dist);
   X3=uint16(xoff+cos(beta)*dist);
   Y3=uint16(yoff+sin(beta)*dist);
   X4=uint16(xoff-cos(beta)*dist);
   Y4=uint16(yoff-sin(beta)*dist);
    
   mat(Y1, X1)= mat(Y1, X1)+intensity;
   mat(Y2, X2)= mat(Y2, X2)+intensity;
   mat(Y3 ,X3)= mat(Y3, X3)+intensity;
   mat(Y4 ,X4)= mat(Y4, X4)+intensity;
   
 
   e2=2*err;
   if(e2<(2*dx+1)*b2)
      dx=dx+1;
      err=err+(2*dx+1)*b2;
   end
   if e2> -(2*dy-1)*a2
      dy=dy-1;
      err=err-(2*dy-1)*a2;
   end
end
out=mat;